package cn.butcher21.controller;

import cn.butcher21.dao.DaoUser;
import cn.butcher21.dao.DaoWorkImpl.DaoUserImpl;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;

@WebFilter(filterName = "CheckLoginFilter", value = "/index.html")
public class CheckLoginFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) resp;
        HttpSession session = request.getSession();
        if (session.getAttribute("userid") != null) {
            chain.doFilter(req, resp);
        } else {
            response.sendRedirect("login.html");
        }

    }

    public void init(FilterConfig config) throws ServletException {

    }

}
